/*
 * successful test by 20Sep
 */
package twoD.IsoPfem;

import inf.jlinalg.IMatrix;
import inf.jlinalg.MatrixFormat;

public class CST2Demo {

	public void test1() {
		Mesh M = new Mesh();

		Node n1 = M.addNode(new Node(0, 0));
		Node n2 = M.addNode(new Node(6, 2));
		Node n3 = M.addNode(new Node(4, 4));

		IEdge e1 = M.addEdge(new StraightEdge(n1, n2));
		IEdge e2 = M.addEdge(new StraightEdge(n2, n3));
		IEdge e3 = M.addEdge(new StraightEdge(n3, n1));

		IFace f = M
				.addFace(new FlatFace(new Node[] { n1, n2, n3 }, e3, e2, e1));

		Triangle T = new Triangle(f);

		M.addGeometry(T);

		RealTable realTable = new RealTable(288, 1.0 / 3);
		realTable.setThickness(1);

		ElasticStructure struct = new ElasticStructure(M);

		IElement e = struct.addElement(new CST2(realTable, T));

		IMatrix ke = e.computeTangentStiffnessMatrix();
		System.out.println(MatrixFormat.format(ke));

		Constraint c = new Constraint(false, false);
		n1.setConstraint(c);
		n3.setConstraint(c);
		e3.setConstraint(c);

		Force F = new Force(0, -1e3);
		n2.setForce(F);

		struct.solveLinearStaticEquilibrium();
		struct.listingDisplacements();
	}

	public static void main(String[] args) {
		new CST2Demo().test1();
	}

}
